﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Meebey.SmartIrc4net;
using System.Threading;
namespace IrcYo
{
    public partial class IrcDuellControl : UserControl
    {
        IrcClient irc;
        Opfer op1;
        Opfer op2;
        string op1msg;         
        string op2msg;

        public string Op1Nick
        {
            get { return op1.Nick; }
        }
        public string Op2Nick
        {
            get { return op2.Nick; }
        }

        public IrcDuellControl(IrcClient irc, Opfer op1, Opfer op2, string op1msg, string op2msg)
        {
            InitializeComponent();
            this.op1 = op1;
            this.op2 = op2;
            this.op1msg = op1msg;
            this.op2msg = op2msg; 
            lblDescribtion.Text = op1.Nick + " vs " + op2.Nick;
            this.irc = irc;

        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            // Begrüßen :D
            listChat.Items.Add("Zu " + op1.Nick + ": " + op1msg);
            listChat.Items.Add("Zu " + op2.Nick + ": " + op2msg); 
            irc.RfcPrivmsg(op1.Nick, op1msg);
            irc.RfcPrivmsg(op2.Nick, op2msg); 
        }

        public void OnChat(IrcEventArgs e)
        {
            addMessage(e.Data.Nick, e.Data.Message);

            if (e.Data.Nick == op1.Nick)
            {
                irc.RfcPrivmsg(op2.Nick, e.Data.Message); 
            }
            else
            {
                irc.RfcPrivmsg(op1.Nick, e.Data.Message); 
            }
        }

        public void addMessage(string nick,string msg)
        {
            DateTime now = DateTime.Today; 
            listChat.Items.Add("["+now.ToShortTimeString()+"]<" + nick + "> " + msg);
        }
    }
}
